<?
require_once  '../classes/ConnectionDB.php';
require_once  '../classes/ClasseDataManager.php';
require_once  '../classes/TestDataManager.php';
require_once  '../classes/TestStudentiDataManager.php';
require_once  '../bean/Domanda.php';

$connection =ConnectionDB::getInstance()->connectToDB();

$codiceTest = $_GET["codiceTest"];
$codiceStudente = $_GET["codiceStudente"];
$chiaveTest = $_GET["chiaveTest"];

//$domande = TestDataManager::getInstance()->getDomandeInTestSottomessiForStudent($connection, $codiceTest, $codiceStudente);
$listaDomandeTmp=TestStudentiDataManager::getInstance()->getSeedQuestion($connection, $codiceStudente, $codiceTest, $chiaveTest);
$domande = explode("-", $listaDomandeTmp);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Nuova sottomissione Test Pdf - step 3 - </title>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/prototype.js" type="text/javascript"></script>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/scriptaculous/effects.js" type="text/javascript"></script>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/glassbox/glassbox.js" type="text/javascript"></script>
        <style type="text/css">
            @import url("../css/style.css");
            table{
                width: 100%;
            }

            #tableResults td{
                text-align: center;
            }

            #results {
                padding-top: 3%;
                margin-left: -5px;
            }



        </style>
        <script type="text/javascript">
            path_to_root_dir = "../glassboxLatest/glassbox.2.0.0/";
            var listaDomande;
            var numItem=10;
            var currentIndex=0;

            window.onload = function()
            {
                var testForm = new GlassBox();
                testForm.init( 'results', '1040px', '490px', 'auto','',true, false);
                testForm.ipos();
                testForm.appear();
            }

            function inserisci(codiceDomanda)
            {
                var client = xXMLHttpRequest();
                client.onreadystatechange = function()
                {
                    document.getElementById('risOp'+codiceDomanda).style.backgroundColor="green";
                }

                var param = "codiceDomanda="+ codiceDomanda +
                    "&rispostaData="+document.getElementById('risp' +codiceDomanda).value+
                    "&operation=sendResultsPdf"+
                    "&codiceTest=<?= $codiceTest ?>" +
                    "&codiceStudente=<?= $codiceStudente ?>" +
                    "&chiaveTest=<?= $chiaveTest ?>";
//                alert("param " +param);
                client.open("POST", "newTestListener.php", true);
                client.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

                client.send(param);



            }

            function xXMLHttpRequest()
            {

                var client = null;
                if (window.XMLHttpRequest)
                {
                    client=new XMLHttpRequest();
                }
                // code for IE
                else if (window.ActiveXObject)
                {
                    client=new ActiveXObject("Microsoft.XMLHTTP");
                }

                return client;
            }

        </script>
    </head>
    <body>
        <form name="formInsert" id="formInsert" method="POST" action="newTestListener.php">
            <input type="hidden" name="operation" value="sendResultsPdf"/>
            <input type="hidden" name="codiceTest" value="<?= $codiceTest ?>"/>
            <input type="hidden" name="codiceStudente" value="<?= $codiceStudente ?>"/>
            <input type="hidden" id="codiceDomanda" name="codiceDomanda" value=""/>
            <input type="hidden" id="risposta" name="rispostaData" value=""/>
            <input type="hidden" id="chiaveTest" name="chiaveTest" value="<?= $chiaveTest ?>" />
        </form>
        <?php include '../portal/header.php';?>
        <center>
            <div id="results">
                <div id="resultsCont">

                    <table border='1' id='tableResults' cellpadding='5'>
                        <tr>
                            <th>Dettaglio Domanda : </th>
                            <th>Codice Domanda</th>
                            <th>Testo Domanda</th>
                            <th>Risposte possibili</th>
                            <th>Risposta data</th>
                            <th>Inserisci</th>
                            <th>Risultato Operazione</th>

                        </tr>
                        <?for($i=0;$i<count($domande);$i++)
                        {
                            $domanda = TestDataManager::getInstance()->getDomanda($connection, $domande[$i]);
                            ?>

                        <tr>
                            <td><a href="../report/detailQuestion.php?codiceDomanda=<?= $domanda->getCodiceDomanda(); ?>"<img src='../images/icons/PNG/Magnifying Glass.png' height='30' width='30' title='Registra risultati studente' border='0'/></a></td>
                            <td><?= $domanda->getCodiceDomanda(); ?></td>
                            <td><?= $domanda->getTestoDomanda(); ?></td>
                            <td><b>
                                <? if($domanda->getTipologia()=='1') echo 'V / F';
                                else echo '1, 2, 3, 4'
                                ?></b>
                            </td>
                            <td>
                                <input type="text" id="risp<?= $domanda->getCodiceDomanda(); ?>" name="risp" size="2" /></td>
                            <td><input type="button" id="button<?= $domanda->getCodiceDomanda(); ?>"value="Inserisci" onclick="this.disabled=true;inserisci(<?= $domanda->getCodiceDomanda(); ?>)" </td>
                            <td id="risOp<?= $domanda->getCodiceDomanda(); ?>">&nbsp;</td>
                        </tr>
                            <?}?>


                    </table>
                </div>
            </div>
        </center>
    </body>
</html>
